<!--
	作者：Sariay
	时间：2018-09-25
	描述：There may be a bug, but don't worry, QiLing(器灵) says that it can work normally!
-->
<!DOCTYPE html>
<html class="html-loading">
		

<head><meta name="generator" content="Hexo 3.9.0">
	<!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <title>
    
      CPU信息获取 | Sunow&#39;s Club
    
  </title>
  <meta name="author" content="sunowsir">
  <meta name="keywords" content>
  <meta name="description" content="This is Sunowsir&#39;s club.">
	<!-- favicon -->
  <link rel="shortcut icon" href="/img/favicon.ico">

  <!-- css -->
  <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/Annie.css">
  
  <!-- jquery -->
	<script src="/js/jquery.min.js"></script>

  <!-- leancloud -->
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
<script src="/js/leancloud.js"></script><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>
	<body>
        <!-- hexo-inject:begin --><!-- hexo-inject:end --><!--动态线条背景-->
        <script type="text/javascript"
        color="220,220,220" opacity='0.7' zIndex="-2" count="200" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js">
        </script>
		<!-- Preloader -->

	<div id="preloader">
		<div class="pre-container">
			
				<div class="spinner">
					<div class="double-bounce1"></div>
					<div class="double-bounce2"></div>
				</div>
						
		</div>
	</div>


<!-- header -->
<header class="fixbackground" data-img-mode="random" data-normal-src="/img/1.jpg" data-random-max="110" data-random-src="https://sariay.github.io/Random-img/">
	<div class="mask">
		<!-- Logo and navigation -->
		<div class="h-header">
			<div id="logo">
				<a href="/">
						
						<img src="/img/logo.png" alt="Logo">
					
				</a>
			</div>
			
			<div id="navigation-show">
				<ul>
	
		<li class="menu-home">
			<a href="/" class="menu-item-home">主页</a>
		</li>
	
		<li class="menu-archive">
			<a href="/archives" class="menu-item-archive">归档</a>
		</li>
	

	
		<li class="menu-search">
			<a href="javascript:;" class="popup-trigger">搜索</a>
		</li>
	
</ul>
			</div>				
		</div>

		<!-- motto -->
		<div class="h-body">	
			
				<p class="motto"></p>
			
		</div>
		
		<!-- others: such as time... -->			
		<div class="h-footer">
			<a href="javascript:;" id="read-more"><i class="fa fa-angle-double-down" aria-hidden="true"></i>
			</a>

			
				<!-- 
	This is only a demo, please go to "https://time.is" to set your city time! 
-->
<style type="text/css">
	.header-date {
		font-size: 1.6rem;
		color: #fff;
		position: absolute;
		bottom: 5px;
		right: 1rem;
		writing-mode: tb-rl;
	}	
	
	.header-date a {
		border-bottom: none;
	}

	@media only screen and (max-width: 768 ) {
		.header-date {
			font-size: 1rem;
		}			
	}
</style>
<div class="header-date">
	<a href="https://time.is/Beijing" id="time_is_link" rel="nofollow" ></a>
	<span id="Beijing_z43d"></span>
</div>
<script src="//widget.time.is/zh.js"></script>
<script>
	time_is_widget.init({
		Beijing_z43d:{
			template:"DATE", 
			date_format:"year年 monthname dnum日"
		}
	});
</script>
			
		</div>
	</div>
</header>

<div id="navigation-hide">
	<!-- Progress bar -->
	<div id="progress-bar"></div>

	<!-- Progress percent -->
	<div id="progress-percentage"><h1>0.0%</h1></div>

	<div class="toc-switch"><span class="switch-button">目录</span></div>

	<!-- Page title -->
	<p>
		
			当前文章&nbsp;:&nbsp;《CPU信息获取》
		
	</p>

	<!-- Nav trigger for navigation-H-->
	<a class="nav-trigger"><span></span></a>
</div>

<!-- Navigation in div(id="navigation-H") -->
<nav class="nav-container" id="cd-nav">
	<div class="nav-header">
		<h3>Navigation</h3>
		<a href="javascript:;" class="nav-close"></a>
	</div>
	<div class="nav-body">
		<ul>
	
		<li class="menu-home">
			<a href="/" class="menu-item-home">主页</a>
		</li>
	
		<li class="menu-archive">
			<a href="/archives" class="menu-item-archive">归档</a>
		</li>
	

	
		<li class="menu-search">
			<a href="javascript:;" class="popup-trigger">搜索</a>
		</li>
	
</ul>
	</div>
	<div class="nav-footer">
		<ul>
	
		<li>
			<a href="http://github.com/sunowsir" target="_blank">
				<i class="fa fa-github"></i>
			</a>
		</li>
			
</ul>

	</div>
</nav>
			
		<!--main-->
		<main>
			<!--
	时间：2018-11-17
	描述：
		插件名称：katelog.min.js
		插件作者：KELEN
		插件来源: https://github.com/KELEN/katelog
-->
	 

<div class="layout-post">
	<div id="layout-post">
	<div class="article-title">
		<i class="fa fa-paper-plane-o" aria-hidden="true"></i>
		
	<a href="/2019/09/02/CPU信息获取/" itemprop="url">
		CPU信息获取
	</a>

	</div>

	<div class="article-meta">
		<span>
			<i class="fa fa-calendar"></i>
			


	发布于

	<a href="/2019/09/02/CPU信息获取/" itemprop="url">
		<time datetime="2019-09-02T08:50:49.000Z" itemprop="datePublished">
	  		2019-09-02
	  </time>
	</a>
	&nbsp;





			




	更新于

	<a href="/2019/09/02/CPU信息获取/" itemprop="url">
		<time datetime="2019-09-02T08:50:49.000Z" itemprop="dateUpdated">
	  		2019-09-29
	  </time>
	</a> 



		</span>
		<span>
			<i class="fa fa-tags"></i>
			
	
		<a href="/tags/script/" class=" ">
			script
		</a>
	
		<a href="/tags/linux/" class=" ">
			linux
		</a>
	
		
		</span>
		
		



	</div>

	<div class="article-content" id="article-content">
		<ul>
<li>
<p>准备知识</p>
<ol>
<li>
<p><code>/proc</code>文件系统是一个伪文件系统，该文件系统中存储着内核控制相关信息，通俗点说就是这个目录是虚拟的，它受内核直接控制，存储与内核控制相关的数据，与其他目录不同的是<code>/proc</code>目录不是真实存储在硬盘中的，它的数据存储在内存中，但是由于它和其他目录一样把自己注册到虚拟文件系统层了，所以我们还是能看到这个目录相关信息，然而只有虚拟文件系统层调用它的时候，他才会建立相关文件和目录并与内核沟通获取相关信息。</p>
</li>
<li>
<p>上面我们说道<code>/proc</code> 文件系统存储着内核控制相关信息的目录，该目录下的<code>/proc/stat</code>文件存储的是<code>CPU</code>相关信息，我们想要获取<code>CPU</code>相关信息最直接和最快速的方式就是读取该文件，其实<code>Linux下</code>很多的工具都是读取的这个文件。在这个文件中包含了所有的<code>CPU</code>活动信息，并且该文件中所有值都是从系统启动算起直到访问文件的这一刻的数据。如下就是某一刻<code>/proc/stat</code>文件中的数据：</p>
<p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">cpu  499312 1086 227835 10498412 3803 0 10904 0 0 0</span><br><span class="line">cpu0 125361 278 56675 2626355 450 0 2242 0 0 0</span><br><span class="line">cpu1 124704 288 57768 2627741 350 0 2168 0 0 0</span><br><span class="line">cpu2 130284 261 55543 2620559 2442 0 1762 0 0 0</span><br><span class="line">cpu3 118961 258 57848 2623755 560 0 4731 0 0 0</span><br><span class="line">intr 46393945 9 924 0 0 0 0 0 0 1 14751 0 0 215 0 0 0 139800 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4476 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 408029 0 283839 7963609 40 945 1535489 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span><br><span class="line">ctxt 124171702</span><br><span class="line">btime 1539737966</span><br><span class="line">processes 626819</span><br><span class="line">procs_running 4</span><br><span class="line">procs_blocked 0</span><br><span class="line">softirq 27922585 9163685 6158929 26 485 278010 0 160301 6495615 0 5665534</span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>数据单位：jiffies</p>
</blockquote>
<ul>
<li>
<p>如上数据中从cpu到cpu3五行（从左到右按顺序）每一列的含义如下：</p>
<ol>
<li><code>user</code>：如上<strong>499312</strong>、<strong>125361</strong>、<strong>124704</strong>等，用户态时间。</li>
<li><code>nice</code>：如上<strong>1086</strong>等第二列数据，<code>nice</code>值为负数的进程所占时间。</li>
<li><code>system</code>：如上第三列数据，核心时间。</li>
<li><code>idle</code>：如上第四列数据，除硬盘IO等待时间之外的时间。</li>
<li><code>iowait</code>：如上第五列数据，硬盘IO等待时间。</li>
<li><code>irq</code>：如上第六列数据，硬中断时间。</li>
<li><code>softirq</code>如上第七列数据，软中断时间。</li>
</ol>
<p>$$
CPU_{time}=user_{line:1} +nice_{line:2} + system_{line:3} + idle_{line:4} + iowait_{line:5} + irq_{line:6} + sortirq_{line:7}
$$</p>
</li>
<li>
<p>剩下的几行：</p>
<ol>
<li><code>initr</code>：中断次数</li>
<li><code>ctxt</code>：交换次数</li>
<li><code>btime</code>:从系统启动到访问文件为止的时间。</li>
<li><code>processes</code>：任务数。</li>
<li><code>procs_runing</code>：当前运行队列的任务数。</li>
<li><code>procs_blocked</code>：当前被阻塞的任务数。</li>
</ol>
</li>
<li>
<p><code>CPU</code>利用率计算可以采用两点采样取差值的方式：</p>
<p>$$
CPU_{usage} = (idle_{第二次采样} - idle_{第一次采样}) / (CPU_{time第二次采样} - CPU_{time第一次采样}) * 100
$$</p>
</li>
</ul>
</li>
<li>
<p>CPU温度的获取：</p>
<p>cpu温度存储在<code>/sys/class/thermal/thermal_zone0/temp</code>中，读取出的数值需要除以1000。</p>
</li>
<li>
<p>bash 工具：</p>
<ol>
<li><code>cat</code>：工具用来强制读取一个文件。</li>
<li><code>gerp</code>：工具用来筛选数据。</li>
<li><code>awk</code>：用来处理数据。</li>
<li><code>uptime</code>：获取cpu负载信息</li>
</ol>
</li>
<li>
<p>bash 数值计算：</p>
<p>bash中的数值计算比较方便的方式是双小括号：</p>
<p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">num=0</span><br><span class="line">((num++)) <span class="comment"># 在双小括号中可以正常使用C语言的数值计算语法</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$&#123;num&#125;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 结果输出---------------</span></span><br><span class="line">1</span><br></pre></td></tr></table></figure></p>
</li>
</ol>
</li>
<li>
<p>代码
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line">time_and_load=`date +<span class="string">"%Y-%m-%d__%H:%M:%S "</span>``uptime | tr -s <span class="string">" "</span> <span class="string">"\n"</span> | tr -s <span class="string">","</span> <span class="string">" "</span> | awk NF | tail -3 | tr -s <span class="string">"\n"</span> <span class="string">" "</span>`</span><br><span class="line"></span><br><span class="line"><span class="comment"># 0.5s 前</span></span><br><span class="line"><span class="comment"># 开机后总时间</span></span><br><span class="line">cpu_local1=`cat /proc/<span class="built_in">stat</span> | grep  -w <span class="string">"cpu"</span> | awk <span class="string">'&#123;printf("%d", $2 + $3 + $4 + $5 + $6 + $7 + 8);&#125;'</span>`</span><br><span class="line"><span class="comment"># 开机后累计空闲</span></span><br><span class="line">cpu_idle1=`cat /proc/<span class="built_in">stat</span> | grep  -w <span class="string">"cpu"</span> | awk <span class="string">'&#123;printf("%d", $5);&#125;'</span>`</span><br><span class="line"></span><br><span class="line">sleep 0.5s</span><br><span class="line"></span><br><span class="line"><span class="comment"># 0.5s 后</span></span><br><span class="line"><span class="comment"># 开机后总时间</span></span><br><span class="line">cpu_local2=`cat /proc/<span class="built_in">stat</span> | grep  -w <span class="string">"cpu"</span> | awk <span class="string">'&#123;printf("%d", $2 + $3 + $4 + $5 + $6 + $7 + 8);&#125;'</span>`</span><br><span class="line"><span class="comment"># 开机后累计空闲</span></span><br><span class="line">cpu_idle2=`cat /proc/<span class="built_in">stat</span> | grep  -w <span class="string">"cpu"</span> | awk <span class="string">'&#123;printf("%d", $5);&#125;'</span>`</span><br><span class="line"></span><br><span class="line"><span class="comment"># 0.5s 内</span></span><br><span class="line">((cpu_local = <span class="variable">$cpu_local2</span> - <span class="variable">$cpu_local1</span>))</span><br><span class="line">((cpu_idle = <span class="variable">$cpu_idle2</span> - <span class="variable">$cpu_idle1</span>))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 计算cpu占用率</span></span><br><span class="line">cpu_occu=`<span class="built_in">echo</span> <span class="string">"<span class="variable">$cpu_local</span> <span class="variable">$cpu_idle</span>"</span> | awk <span class="string">'&#123;printf("%.2f%%", (1 - $2 / $1) * 100);&#125;'</span>`</span><br><span class="line"></span><br><span class="line"><span class="comment"># CPU温度</span></span><br><span class="line">cpu_temp_info=`cat /sys/class/thermal/thermal_zone0/temp | awk <span class="string">'&#123;</span></span><br><span class="line"><span class="string">        if ($1 &gt;= 1000 &amp;&amp; $1 &lt; 50000) &#123;</span></span><br><span class="line"><span class="string">            printf("%.2f normal", $1 / 1000);</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">        else if ($1 &gt;= 50000 &amp;&amp; $1 &lt;= 70000) &#123;</span></span><br><span class="line"><span class="string">            printf("%.2f note", $1 / 1000);</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">        else &#123;</span></span><br><span class="line"><span class="string">            printf("%.2f warning", $1 / 1000);</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">    &#125;'</span>`</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;time_and_load&#125;</span><span class="variable">$&#123;cpu_occu&#125;</span> <span class="variable">$&#123;cpu_temp_info&#125;</span>"</span></span><br></pre></td></tr></table></figure></p>
</li>
</ul>
	
	</div>
	
	<div id="current-post-cover" data-scr="https://w.wallhaven.cc/full/wy/wallhaven-wyd5jx.jpg"></div>

	<!-- relate post, comment...-->
	<div class="investment-container">
		<div class="investment-header">
			<div class="investment-title-1">
				<div class="on">相关文章</div>
				<div>评论</div>
				<div>分享</div>
			</div>
			<div class="investment-title-2">	            
				
	<span>
		<a href="javascript: window.scrollTo(0, 0);">返回顶部</a>
		
			<a href="/2019/09/02/HDU-1276/" title="HDU-1276" rel="prev">
				&laquo;上一篇
			</a>
		
		
			<a href="/2019/09/02/POJ-1979/" title="POJ-1979" rel="next">
				下一篇&raquo;
			</a>
			
	</span>


      		
			</div>	
		</div>
		
		<div class="investment-content">
			<div class="investment-content-list">
				

<div class="relate-post">
	
		<ul>
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/BASH脚本实现素数线性筛/" title="BASH脚本实现素数线性筛">
								BASH脚本实现素数线性筛			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								

知识准备


for循环
12345678910111213141516171819202122232425for i in `seq 1 10`;do	echo $&#123;i&#125;done#执行结果---------1...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/BASH脚本实现素数线性筛/" title="BASH脚本实现素数线性筛">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/83/wallhaven-8396gk.jpg" alt="BASH脚本实现素数线性筛"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/磁盘信息获取/" title="磁盘信息获取">
								磁盘信息获取			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								

知识准备：


df:该工具用来获取文件系统挂载信息。


awk：该工具用来处理 df的数据。




代码：
1234567891011121314151617#!/bin/bashdf -m | grep "^/dev/" ...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/磁盘信息获取/" title="磁盘信息获取">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/j5/wallhaven-j5ymwp.jpg" alt="磁盘信息获取"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/进程信息获取/" title="进程信息获取">
								进程信息获取			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								

知识准备：

ps 该工具用来获取进程信息
awk该工具用来处理数据



代码
1234567891011121314151617181920#!/bin/bashps -aux | awk -v last_all=$(ps -...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/进程信息获取/" title="进程信息获取">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/5w/wallhaven-5w3l27.jpg" alt="进程信息获取"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/内存信息获取/" title="内存信息获取">
								内存信息获取			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								

free：该工具用来获取内存信息


grep：该工具用来筛选数据


awk'：该工具用来处理数据


代码：
123456#!/bin/bashfree -m | grep "^Mem" | awk -v last_per=$...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/内存信息获取/" title="内存信息获取">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/xl/wallhaven-xldjkv.jpg" alt="内存信息获取"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/系统信息获取/" title="系统信息获取">
								系统信息获取			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								
欢迎大家转载，转载请注明出处，谢谢！



知识准备

date：获取当前时间
/etc/issue：系统版本信息
/proc/loadavg：负载信息
df：获取磁盘信息
free：内存信息
/sys/class/thermal/...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/系统信息获取/" title="系统信息获取">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/5w/wallhaven-5wm328.jpg" alt="系统信息获取"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/用户信息获取/" title="用户信息获取">
								用户信息获取			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								
欢迎大家转载，转载请注明出处，谢谢！



知识准备

w：获取当前登录信息
grep：对数据进行筛选
cut：对字符串进行剪切
sort：排序
uniq：统计每个字符串个数
head：显示开头几行
awk：文本处理工具



代码...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/用户信息获取/" title="用户信息获取">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/vg/wallhaven-vgdj1m.jpg" alt="用户信息获取"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/服务器健康监控/" title="服务器健康监控">
								服务器健康监控			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								
项目地址



简介：
使用C语言和bash脚本实现的服务器健康监控系统。服务器端通过执行bash脚本获取健康信息，利用socket即时发送到监控端主机。


监测数据类型：

采用bash脚本获取相关信息


cpu
内存
硬盘
...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/服务器健康监控/" title="服务器健康监控">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/2e/wallhaven-2eop2x.jpg" alt="服务器健康监控"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/27/八大排序算法总结/" title="八大排序算法总结">
								八大排序算法总结			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 27日, 2019				
							</p>
							<p class="relate-post-content">
								直接插入排序算法


概述
直接插入排序算法在逻辑上将整体数据分为两部分，一部分是已排序部分，另一部分是待排序部分 。
排序的过程是：在待排序部分逐步的拿出一个元素，将其插入到已排序部分中合理的位置 。


适用场景
插入排序在对几乎...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/27/八大排序算法总结/" title="八大排序算法总结">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/ox/wallhaven-oxj7mm.jpg" alt="八大排序算法总结"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/16/hexo低成本搭建静态网页博客/" title="hexo低成本搭建静态网页博客">
								hexo低成本搭建静态网页博客			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 16日, 2019				
							</p>
							<p class="relate-post-content">
								引言
好多同学有写博客的习惯，也有各大例如csd*、简*等博客平台。
但是这些平台毕竟是盈利平台，无法做到对自己的博客完全掌控，有一丝丝的不爽快。想要DIY一下几乎不可能。在这里推荐同学们自己动手丰衣足食。
准备知识

github最...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/16/hexo低成本搭建静态网页博客/" title="hexo低成本搭建静态网页博客">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/45/wallhaven-45yd68.jpg" alt="hexo低成本搭建静态网页博客"/>
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="/2019/09/02/HDU-1276/" title="HDU-1276">
								HDU-1276			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 2日, 2019				
							</p>
							<p class="relate-post-content">
								

题目描述
某部队进行新兵队列训练，将新兵从一开始按顺序依次编号，并排成一行横队，训练的规则如下：从头开始一至二报数，凡报到二的出列，剩下的向小序号方向靠拢，再从头开始进行一至三报数，凡报到三的出列，剩下的向小序号方向靠拢，继续从头...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="/2019/09/02/HDU-1276/" title="HDU-1276">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://w.wallhaven.cc/full/ym/wallhaven-ym28eg.jpg" alt="HDU-1276"/>
							</a>
						</div>
					</li>											
			
			
		</ul>
	
</div>	
			</div>
			<div class="investment-content-list">
				<div class="layout-comment">

	

		

			<!-- I don't know !!!-->
			<div>Please check the comment setting in config.yml of hexo-theme-Annie!</div>
			
		
		
	

</div>
			</div>
			<div class="investment-content-list">
				<div class="layout-share">
	
	

		
			
			<!-- socialShare share -->
			<div class="social-share"></div>

<!--  css & js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">
<script async src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>
			
		
		
	
</div>


			</div>
		</div>	
	</div>
	</div>
</div>



	<!-- leancloud -->
	<!--
	时间：2018-11-27
	描述：
		文章访问量：visitors
		文章喜欢量：likes	
		文章排行榜：topNPost
		其他得说明：
			01-Cookie相关的函数 
				https://blog.csdn.net/somehow1002/article/details/78511541（Author：somehow1002）
			02-visitors相关的函数 
				https://blog.csdn.net/u013553529/article/details/63357382（Author：爱博客大伯）
				https://notes.doublemine.me/2015-10-21-为NexT主题添加文章阅读量统计功能.html（Author：夏末）
			03-topNPost相关的函数
				https://hoxis.github.io/hexo-next-read-rank.html（Author：hoxis）
			04-likes相关的函数，
				参考了01 & 02进行简单的设计与实现
-->


	


<!-- show math formula -->

	<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
	<script type="text/x-mathjax-config">
		MathJax.Hub.Config(
			{ 
				tex2jax: {
					inlineMath: [['$','$'], ['\\(','\\)']]
				} 
			}
		);
	</script>



	 
	<script src="/plugin/clipboard/clipboard.js"></script>
	<script>
		// Copy code !
	    function codePreprocessing() {
	        $("#article-content .highlight").each(function() {

	            $(this).wrap('<div id="post-code"></div>');

	        })

	        $("#article-content #post-code").each(function() {

	            $(this).prepend('<nav class="copy-nav"><span><i class="code-language"></i></span></nav>');

	        })

	        $("#article-content .copy-nav").each(function() {
	            var temp = $(this).next().attr('class'),
	                language = ((temp.length > 9) && (temp != null)) ? temp.substr(10) : "none"; //why 9? Need to check language?

	            $(this).find('.code-language').text(language);

	            $(this).append('<span class="copy-btn"><i class="fa fa-copy" aria-hidden="true"></i></span>');

	        });
	    }

		function codeCopy() {
		    $('#article-content #post-code').each(function(i) {
		        var codeCopyId = 'codeCopy-' + i;

		        var codeNode = $(this).find('.code'),
		            copyButton = $(this).find('.copy-btn');

		        codeNode.attr('id', codeCopyId);
		        copyButton.attr('data-clipboard-target-id', codeCopyId);
		    })

		    
			var clipboard = new ClipboardJS('.copy-btn', {
					target: function(trigger) {
						return document.getElementById(trigger.getAttribute('data-clipboard-target-id'));
					}
		      	});

			//pure js
			function showTooltip(elem, msg) {		   
				elem.setAttribute('aria-label', msg);
				elem.setAttribute('class', 'copy-btn copy-status');
				setTimeout(function() {
					elem.setAttribute('class', 'copy-btn');
				}, 2000);
			}

			clipboard.on('success', function(e) {
			    e.clearSelection();
			    console.info('Action:', e.action);		   
			    console.info('Trigger:', e.trigger);
			    showTooltip(e.trigger, 'Copied!');
			    
			});
			clipboard.on('error', function(e) {
			    console.error('Action:', e.action);
			    console.error('Trigger:', e.trigger);
			});
		

		}

		if ($('.layout-post').length) {
		    codePreprocessing();
		    codeCopy();
		} 
	</script>





<link rel="stylesheet" href="/plugin/fancybox/jquery.fancybox.css">
<script src="/plugin/fancybox/jquery.fancybox.js"></script>

<script type="text/javascript">
	var titleID = $('.article-title a'),
		imageID = $('.article-content img'),
		videoID = $('.article-content video');

	var postTitle = titleID.text() ? titleID.text() : "No post title!";

	imageID.each(function() {
		var imgPath = $(this).attr('src'),
			imgTitle = $(this).attr('alt') ? $(this).attr('alt') : "No image description!";

		//给每个匹配的<img>元素打包, 即添加父元素<a>
		$(this).wrap('<a data-fancybox="gallery" data-caption=" 《 ' + postTitle + ' 》 ' + imgTitle + ' "  href=" ' + imgPath + ' "> </a>');
	});

	videoID.each(function() {
		var videoPath = $(this).attr('src');

		//给每个匹配的<img>元素打包, 即添加父元素<a>
		$(this).wrap('<a data-fancybox href=" ' + videoPath + ' "> </a>');
	});
	//TODO：支持html5 video

	if($('#layout-post').length) {
		$('[data-fancybox="gallery"]').fancybox({
			loop: true,
			buttons: [
				"zoom",
				"share",
				"slideShow",
				"fullScreen",
				//"download",
				"thumbs",
				"close"
			],
			protect: false
		});
	}
</script>
		</main>

		<!--footer-->
		<footer>
	<div class="social">
		<ul>
	
		<li>
			<a href="http://github.com/sunowsir" target="_blank">
				<i class="fa fa-github"></i>
			</a>
		</li>
			
</ul>

	</div>
		
	<div class="copyright">
		<p>
			 
				&copy;2019, content by sunowsir. All Rights Reserved.
			
			
			

	<!-- busuanzi -->
	<!-- busuanzi -->

		
	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
	

		<span id="busuanzi_container_page_pv">
	  		本文总阅读量<span id="busuanzi_value_page_pv"></span>次
		</span>

	




		</p>
		<p>
			<a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a> Theme <a href="https://github.com/Sariay/hexo-theme-Annie" title="Annie" target="_blank" rel="noopener">Annie</a> by Sariay.
			<a href="javascript:zh_tran('s');" class="zh_click" id="zh_click_s">简体</a> 
			<a href="javascript:zh_tran('t');" class="zh_click" id="zh_click_t">繁體</a>				
		</p>
	</div>		
</footer>
		
	<!-- set '1' to show motto in all pages! -->

	<script src="/plugin/motto/motto.js"></script>
	
	<script type="text/javascript">
		$(".motto").html( getMingYanContent() );
	</script>	




	<!--
	时间：2018-10-3
	描述：
		插件名称：hexo-generator-search-zip
		插件来源: https://github.com/SuperKieran/hexo-generator-search-zip
		代码参考：https://github.com/SuperKieran/TKL/blob/master/layout/_partial/search.ejs(Include: js & css)	
-->
<div class="popup search-popup local-search-popup" >
	<div class="local-search-container">
		<span class="popup-btn-close">
      		ESC
   		</span>
		<div class="local-search-header">
			<div class="input-prompt">				
			</div>
			<input autocomplete="off" placeholder="Search..." type="text" id="local-search-input">
		</div>
		<div class="local-search-body">
			<div id="local-search-output"></div>
		</div>
		<div class="local-search-footer">
			<div class="topN-post">				
				
								
			</div>
		</div>
	</div>
</div>

<script src="/plugin/search/ziploader.js"></script>
<script src="/plugin/search/search.js"></script>

<script type="text/javascript">
	var search_path = 'search.json',
		zip_Path = '/search.zip',
		version_Path = '/searchVersion.txt',
		input_Trigger = 'auto',
		top_N = '2';

	themeLocalSearch({
		search_path, 
		zip_Path, 
		version_Path, 
		input_Trigger, 
		top_N
	});
</script>


<!-- love effect -->

	<script src="/plugin/love/love.js"></script>


<!-- back to top -->

	
	<div id="totop">
  		<a href="javascript:;"  name="TOTOP" class="fa fa-arrow-up" ></a>
	</div>




<!-- site analysis -->


	<!-- site-analysis -->
	
	
	
	
	
 

<script src="/plugin/vibrant/vibrant.js"></script>
<script src="/plugin/chinese/chinese.js"></script>
<script src="/plugin/imgLazyLoader/yall.min.js"></script>
<script src="/plugin/imgResize/jquery.resizeimagetoparent.min.js"></script>
<script src="/plugin/nicescroll/jquery.nicescroll.js"></script>
<script src="/js/resizediv.js"></script>
<script src="/js/main.js"></script><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config("");
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->
	</body>	
</html>
